<template>
  <div class="album" v-if="arr">
    <div class="albumListTop" v-if="datas">
      <div class="albumListTopItem" >
        <span
          class="iconfont icon-fanhuipt icona"
          @click="$router.go(-1)"
        ></span>
        <p>{{ datas.album.name }}</p>

        <div>
            <span :class="['iconfont', flag? 'icon-xihuan-kongpt': 'icon-xihuan-wangyiicon']" @click="albumIcon(datas.album.id)"></span>
            <!-- <span class="iconfont icon-shoucang-tianchong"></span> -->
        </div>
      </div>
      <img :src="datas.album.picUrl" alt="" />


    </div>
    <div class="albumListBottom">
      <div class="single" v-for="(item, index) in arr" :key="item.id" @click="albumList(item.id)">
        <p>{{ index + 1 }}</p>
        <div class="itemName">
          <h4>{{ item.name }}</h4>
          <span v-for="value in item.ar" :key="value.id"
            >{{ value.name }}
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getAlbum,getAlbumSub } from "../../api/singer";
import { Toast } from 'vant';
export default {
  data() {
    return {
      datas: null,
      arr: [], //歌曲信息
      flag:true,
      t:0,
      id:'',
      dasdta:"",
    };
  },
  methods:{
    albumIcon(id){
        if(!this.flag){
          this.flag = true;
          this.t = 0;
          this.id = '';
          Toast.fail('取消收藏');
        }else{

          this.flag = false;
          this.t = 1;
          this.id = id;
          // console.log(id);
         Toast.success('添加收藏');
         
        }
    },
    albumList(id){
      // console.log(id);
      this.$emit("album-list",id)
    }
  },
  created() {
    getAlbum({ id: this.$route.query.id }).then((data) => {
      // console.log(data);
      this.datas = data;
      this.arr = data.songs;
      // console.log(this.arr);
    });
  },
  updated(){
    getAlbumSub({id:this.id,t:this.t}).then(data=>{
      this.dasdta = data 
      // console.log(data);
    })
  }
};
</script>

<style lang="less">
.album {
  width: 100%;
  height: 100%;
  .albumListTop {
    width: 100%;
    height: 271px;
    position: relative;
    top: 0;
    left: 0;
    // z-index: 100;
    .albumListTopItem {
      position: absolute;
      top: 11px;
      left: 11px;
      width: 100% - 5px;
      display: flex;
      justify-content: space-between;
      span {
        width: 25px;
        height: 25px;
        line-height: 25px;
        text-align: center;
        background: rgba(0, 0, 0, 0.3);
        font-size: 18px;
        color: #fff;
        margin-right: 10px;
        border-radius: 50%;
      }
      p {
        font-size: 16px;
        color: #fff;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;

      }
    }
    img {
      width: 100%;
      height: 100%;
    }
  }
  .albumListBottom {
    .single {
      width: 100%;
      height: 55px;
      border-bottom: 2px solid #dadbdc;
      display: flex;
      p {
        display: inline-block;
        width: 44px;
        height: 100%;
        font-size: 16px;
        line-height: 55px;
        text-align: center;
      }
      .itemName {
        width: 100% - 15px;
        height: 100%;
        // margin: auto 0;
        h4 {
          font-size: 16px;
          margin-top: 10px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        span {
          font-size: 12px;
          margin-top: 5px;
          color: #7a7a7a;
        }
      }
    }
  }
}
</style>